package com.sunrise.xdoc.view.list;

import java.io.Serializable;

import javax.faces.bean.ManagedProperty;

import com.sunrise.xdoc.entity.AbstractIdEntity;
import com.sunrise.xdoc.helper.DaoHelper;
import com.sunrise.xdoc.utils.SunriseClassUtils;

/**
 * @param <T>
 *            entity class
 * @author PhanHongPhuc
 */
public abstract class AbstractEntityList<T extends AbstractIdEntity> implements Serializable {
	private static final long serialVersionUID = 1402635417863338564L;

	private T[] selectedEntities;

	private T editedEntity;

	@ManagedProperty(value = "#{daoHelper}")
	private DaoHelper daoHelper;

	@SuppressWarnings("unchecked")
	protected Class<T> getEntityClass() {
		return (Class<T>) SunriseClassUtils.getArgumentClass(getClass());
	}

	public String editAction(T entity) {
		setEditedEntity(entity);
		return "dialog:" + getEditView() + "?modal=true";
	}
	
	public abstract String getEditView();
	
	public DaoHelper getDaoHelper() {
		return daoHelper;
	}

	public void setDaoHelper(DaoHelper daoHelper) {
		this.daoHelper = daoHelper;
	}

	public T[] getSelectedEntities() {
		return selectedEntities;
	}

	public void setSelectedEntities(T[] selectedEntities) {
		this.selectedEntities = selectedEntities;
	}

	public T getEditedEntity() {
		return editedEntity;
	}

	public void setEditedEntity(T editedEntity) {
		this.editedEntity = editedEntity;
	}
}
